import java.util.Arrays;

public class Solution1014 {
    public int maxScoreSightseeingPair(int[] values) {
        int[] f=new int[values.length];
        Arrays.fill(f,Integer.MIN_VALUE);
        f[values.length-1]=values[values.length-1]-(values.length-1);
        for (int i=values.length-2;i>=0;i--){
            f[i]=Math.max(f[i+1],values[i]-i);
        }
        int max=Integer.MIN_VALUE;
        for (int i=0;i<values.length-1;i++){
            max=Math.max(max,values[i]+i+f[i+1]);
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1014().maxScoreSightseeingPair(new int[]{8,1,5,2,6}));
    }
}
